package com.hgw.Demo03_InterpreterPattern.examples;

/**
 * Data time:2021/12/17 19:34
 * StudentID:2019112118
 * Author:hgw
 * Description: 方向节点类，充当终结符表达式角色
 */
public class DirectionNode extends AbstractNode{
    private String direction;

    public DirectionNode(String direction) {
        this.direction = direction;
    }

    // 方向表达式的解释操作
    @Override
    public String interpret() {
        if (direction.equalsIgnoreCase("up")) {
            return "向上";
        } else if (direction.equalsIgnoreCase("down")) {
            return "向下";
        } else if (direction.equalsIgnoreCase("left")) {
            return "向左";
        } else if (direction.equalsIgnoreCase("right")) {
            return "向右";
        } else {
            return "无效指令";
        }
    }
}
